import requests

headers = {
    "sec-ch-ua": "\"Not/A)Brand\";v=\"8\", \"Chromium\";v=\"126\", \"Google Chrome\";v=\"126\"",
    "Referer": "https://www.lottery.gov.cn/",
    "If-None-Match": "\"625cf754-f79\"",
    "If-Modified-Since": "Mon, 18 Apr 2022 05:29:56 GMT",
    "sec-ch-ua-mobile": "?0",
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36",
    "sec-ch-ua-platform": "\"macOS\"",
    "accept": "application/json, text/javascript, */*; q=0.01",
    "accept-language": "zh-CN,zh;q=0.9",
    "priority": "u=1, i",
    "referer": "https://static.sporttery.cn/",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-site",
    "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36",
    "origin": "https://static.sporttery.cn"
}
url = "https://webapi.sporttery.cn/gateway/lottery/getHistoryPageListV1.qry"
saveList = []
# gameNo=35&provinceId=0&pageSize=30&isVerify=1&pageNo=2
for i in range(1, 30):
    params = {
        "gameNo": 35,
        "provinceId": 0,
        "pageSize": 100,
        "isVerify": 1,
        "pageNo": i
    }
    response = requests.get(url, headers=headers, params=params)
    resultList = response.json()['value']['list']
    for item in resultList:
        saveList.append("{}|{}|{}".format(item['lotteryDrawNum'], item['lotteryDrawTime'], item['lotteryDrawResult']))

fh = open("tcp3.txt", 'a')

for item in saveList:
    fh.write(item + "\r\n")
fh.close()
